<?php
namespace Admin\Controller;
use Think\Controller;
class ArticleController extends CommonController {
    //文章列表
    public function index(){
      $this->articles=M('article')->field('id,title,addtime')->limit(0,10)->select();
      $this->display();
    }

    /**
     * 发布文章
     *@ $id int 文章id
     */
    public function edit($id=""){
      $this->article=M('article')->find($id);
      $this->cates=M('category')->order('lv')->select();
      $this->display();
    }
    // 发布文章
    public function addArticle(){
      if(M('article')->add($_POST))
        $this->success('发布成功');
      else $this->error("发布失败");
    }
    // 修改文章
    public function updateArticle(){
      if(M('article')->save($_POST))
        $this->success('修改成功');
      else $this->error("修改失败");
    }
    //删除文章
    public function delArticle(){
      if(M('article')->delete(I('get.id')))
        $this->success('删除成功');
      else $this->error("删除失败");
    }
    //分类列表
    public function category(){
      $this->cates=M('category')->order('lv')->select();
      $this->display();
    }
    //添加分类
    public function addCate(){
      if(M('category')->add(I('post.')))
        $this->success('添加成功');
      else $this->error("添加失败");
    }
    //修改分类
    public function updateCate(){
      if(M('category')->save($_POST))
        $this->success('修改成功');
      else $this->error("修改失败");
    }
    //删除分类
    public function delCate(){
      if(M('category')->delete(I('get.id')))
        $this->success('删除成功');
      else $this->error("删除失败");
    }
}
